let mongoose = require("./db")
let userSchema = new mongoose.Schema({            //用户表
    uname: String,       //用户名称
    phone: String,       //手机号
    password: String,    //密码
    status: Boolean      //状态--是否是第一次登录，是的话就需要跳转到医师认证，不是则跳转到首页
}, { versionKey: false })

let useZen = new mongoose.Schema({             //医师认证表，用于存放用户的医师认证信息
    uid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: "user"
    },
    ptks: String,        //平台科室
    zc: String,          //职业名称
    yiy: String,         //医院名称
    kes: String,         //科室名称
    sanc: String,        //擅长
    ysjj: String        //医生简介
}, { versionKey: false })


// 医师认证中的全部医院
let alldoctors=new mongoose.Schema({
    dname:String,   //医院名称
    daddress:String,//医院地址
    dtype:String,   //医院类型
    ddengji:String  //医院等级
},{versionKey:false})

// 挂号预约中所有的挂号信息
let allGhyy=new mongoose.Schema({
    name:String,
    sex:String,
    age:Number,
    price:Number,
    img:String,
    status:{
        type:Boolean,
        default:true
    },
    isflag:Number
},{versionKey:false})


let way = new mongoose.Schema({ //问诊方式表，用于存放用户的问诊方式信息
    way: String,//问诊方式名称
})
let status = new mongoose.Schema({           //状态表，用于存放用户的状态信息
    status: Number,//问诊状态名称,
    name: String,//状态名称
})

let inquiry = new mongoose.Schema({          //问诊表，用于存放用户的问诊信息
    sid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'status'
    },//问诊状态名称
    wid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'way'
    },//问诊方式名称
    name: String,//患者名称
    sex: String,//患者性别
    age: String,//患者年龄
    content: String,//患者病情描述内容
})
const grab = new mongoose.Schema({ //抢单表，用于存放用户的抢单信息
    name: String,//患者名称
    sex: String,//患者性别
    age: String,//患者年龄
    content: String,//患者病情描述内容
    free: Number,//是否免费//0为免费，1为收费
    quantity: Number//接单数量
})

const patientList = new mongoose.Schema({ //患者列表，用于存放用户的患者列表信息
    name: String,//患者名称
    sex: String,//患者性别
    age: String,//患者年龄
    content: String,//患者病情描述内容
    date: String,//预约日期
    start_time: String,//预约开始时间
    end_time: String,//预约结束时间
    sid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'status'
    },//问诊状态名称
    wid: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'way'
    }//问诊方式名称
})
const followup = new mongoose.Schema({
    department:String,//科室
    content:String,//内容
    medicinename:String,//药品名称
    medicinenumber:Number,//药品数量
    specification:String,//规格
    price:Number,//价格
    condition:String,//用药情况
    patientname:String,//患者姓名
    patientage:String,//患者年龄
    patientsex:String,//患者性别
    patientdisease:String,//患者病症
    sid:{
        type: mongoose.Schema.Types.ObjectId,
        ref: 'status'
    },//问诊状态名称
    img:String//图片
})

let BarkCardsSchema=new mongoose.Schema({  //银行卡表，用于存放用户的银行卡信息
    name:String,       //姓名
    Bank_card_number:String,       //卡号
    bark:{
        type:mongoose.Types.ObjectId,
        ref:"Bark_card"
    },
    ID:String,       //身份证号
    phone:String,       //手机号
    payment_password:String,//密码
    zt:Boolean,       //状态
})


let Bark_cardSchema=new mongoose.Schema({//银行卡类别
    name:String,       //姓名
    path:String,       //头像
    cate:String,       //类别
    
})


let fansSchema=new mongoose.Schema({  //粉丝表
    name:String, //姓名
    path:String, //头像
    gender:String,//性别
    age:String, //年龄
    phone:String,//手机号
})

let evaluateSchama=new mongoose.Schema({  //评价表
    name:String, //姓名
    path:String, //头像
    gender:String,//性别
    age:String, //年龄
    time:Date, //时间
    content:String,//内容
    score:Number,//评分
})

let zjlMy_InformationSchema=new mongoose.Schema({  //我的信息表
    path:String, //头像
})

let hcy_xiaoxSchema=new mongoose.Schema({ //消息列表
    title:String, //标题
    content:String,//内容
    time:Date, //时间
    soupropel:String
},{versionKey:false})



let RxSchema = new mongoose.Schema({ //处方表
    name: String,     //患者姓名
    age: Number,      //患者年龄
    sex: String,      //患者性别
    doctor: String,   //开方医师
    department: String,  //开方科室
    diagnosis: String,   //初步诊断
    opinion: String,      //处理意见
    drug1: String,      //药品1
    specs1: String,      //药品1规格
    drug2: String,      //药品2
    specs2: String,      //药品2规格
    flag: {
        type: Number,
        default: 0
    },       //是否已审核
})



// 用药类型
let phtype=new mongoose.Schema({
    name:String
},{versionKey:false})

// 不同类型药品
let bt=new mongoose.Schema({
    name:String,
    pid:{
        ref:'phtype',
        type:mongoose.Types.ObjectId
    }
},{versionKey:false})
// 药品
let ph=new mongoose.Schema({
     name:String,    //药品名称
     price:Number,   //价格
     mains:String,   //成分
     shape:String,   //形状
     sym:String,    //适应症状
    grade:String,   //规格
    usage:String,   //用法,
    img:String,    //图片,
    nums:Number,
    cy:{
        type:Boolean,
        default:false
    },
    typeid:{
        ref:'bt',
        type:mongoose.Types.ObjectId
    }
},{versionKey:false})

// 处方
let cf=new mongoose.Schema({
    ptname:String, //患者名称
    ptage:Number,  //患者年龄
    ptsex:{
        type:Boolean,
        default:false
    },  //患者性别
    dname:String,//处方医师名字
    ks:String,   //科室
    zd:String,   //初步诊断
    yj:String,   //处理意见
    zt:{
        type:Boolean,
        default:false
    }   //是否设置为常用
    
    
},{versionKey:false})

// 处方药
let cfy=new mongoose.Schema({
    name:String,    //药品名称
     price:Number,   //价格
    //  mains:String,   //成分
     shape:String,   //形状
     sym:String,    //适应症状
    grade:String,   //规格
    usage:String,   //用法,
    img:String,    //图片,
    nums:Number,
    yid:{
        ref:'cf',
        type:mongoose.Types.ObjectId
    }
},{versionKey:false})

let useModel=mongoose.model("user",userSchema)
let useZenModel=mongoose.model("useZen",useZen)
let fansModel=mongoose.model('fans',fansSchema,'fans')
let evaluateModel=mongoose.model('evaluate',evaluateSchama,'evaluate')
let zjlMy_InformationModel=mongoose.model('Information',zjlMy_InformationSchema,'Information')
let BarkCardsModel=mongoose.model('BarkCards',BarkCardsSchema,'BarkCards')
let Bark_cardModel=mongoose.model('Bark_card',Bark_cardSchema,'Bark_card')
let useStatus = mongoose.model('status', status)
let useWay = mongoose.model('way', way)
let useInquiry = mongoose.model('inquiry', inquiry)
let useGrab = mongoose.model('grab', grab)
let usePatientList = mongoose.model('patientList', patientList)
let useFollowup=mongoose.model("followup",followup)
let alldoctorsModel=mongoose.model("alldoctors",alldoctors)
let allGhyyModel=mongoose.model("allGhyy",allGhyy)
let hcy_xiaoxModel=mongoose.model("hcy_xiaox",hcy_xiaoxSchema)
let RxModel = mongoose.model("rxschool", RxSchema, "rxschool")
let phtypemodel=mongoose.model('phtype',phtype)  //药物类型表
let btmodel=mongoose.model('bt',bt)
let phmodel=mongoose.model('ph',ph)   //药品表
let cfmodel=mongoose.model('cf',cf)  //处方
let cfymodel=mongoose.model('cfy',cfy)   //处方药
module.exports={
    useModel,useZenModel,fansModel,evaluateModel,zjlMy_InformationModel,
    BarkCardsModel,Bark_cardModel,useStatus, useWay, useInquiry, useGrab, usePatientList
    ,useFollowup,alldoctorsModel,allGhyyModel,hcy_xiaoxModel,RxModel
    ,phtypemodel,phmodel,cfmodel,cfymodel,btmodel
}